﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DrSoftsFrame.Servers;
using DrSoftsFrame;

namespace PreeRegisterDAL
{
    public class DeptGetDAL
    {
        /// <summary>
        /// 获取科室信息  
        /// </summary>
        /// <param name="deptid"></param>
        /// <returns></returns>
        public static DataSet GetDeptInfo(int ipreeday)
        {
            try
            {

                //刘鹏林   2015-10-22    获取科室时只取有排班的医生科室
//                select d.* from DictDept d  with(nolock) join 
//(
//select b.No_Dept from OPDWorkPerson a  with(nolock) 
//join DictStaff b  with(nolock) on a.iPersonID=b.No_Staff
//where a.bDoctorFlag=1 and b.No_Dept is not null
//group by b.No_Dept
//) e on d.No_Dept=e.No_Dept
//union          
                string sqlstr = string.Format(@"
select * from DictDept  with(nolock) 
where No_Dept in 
(
select iDeptID from OPDWorkPlan  with(nolock)
 where dStartTime between getdate()-1 and DATEADD(d,{0},getdate())
group by iDeptID
)", ipreeday);
                ClinicDb mydb = new ClinicDb();
                DataSet ds = mydb.ExecuteSelect(sqlstr);
                ds.Tables[0].TableName = "DictDept";
                return ds;

            }
            catch (Exception err)
            {

                throw;
            }
        }
    }
}
